﻿namespace Guia.Elements
{
    using System.Windows.Automation;
    using Guia.Elements.PatternServants;
    using Guia.Locator;

    /// <summary>
    /// This class represents a particular header-column of a DataGrid.
    /// </summary>
    public class DataGridHeaderItem : UiElement
    {
        /// <summary>
        /// Represents a helper-servant for the Invoke-pattern.
        /// </summary>
        protected readonly IInvoke InvokeServant;

        /// <summary>
        /// Initializes a new instance of the DataGridHeaderItem class. 
        /// </summary>
        /// <param name="automationElement">The AutomationElement representating the DataGridHeaderItem.</param>
        public DataGridHeaderItem(AutomationElement automationElement)
            : base(automationElement)
        {
            this.InvokeServant = new InvokeImpl(this);
        }

        /// <summary>
        /// Gets the default-condition to find a control by its type.
        /// </summary>
        public static SearchCondition ControlTypeCondition
        {
            get { return SearchCondition.ByControlType(ControlType.HeaderItem); }
        }

        /// <summary>
        /// Sorts all rows according this column.
        /// </summary>
        public void Sort()
        {
            this.InvokeServant.Invoke();
        }
    }
}
